package ru.spies.forms;

import javax.servlet.http.Cookie;

import ru.spies.content.LoginOrRegistrationContent;
import ru.spies.profileClasses.UserInfo;

public class LoginOrRegistrationForm extends FormCreator{
	
	private static LoginOrRegistrationForm statThis=null;
	
	private static final String LOGIN_OR_REGISTER_LINK="loginOrRegister.jsp";

	private LoginOrRegistrationForm() {
		
	}
	
	public static LoginOrRegistrationForm getInstance(){
		if (statThis==null){
			statThis = new LoginOrRegistrationForm();
		}
		return statThis;
	}

	@Override
	protected ICookie childCookieWork(Cookie cookie) {
		return null;
	}

	@Override
	protected String workWithCookieValue(ICookie cook) {
		return null;
	}

	@Override
	public String createThisForm() {
		if (UserInfo.getInstance().isRoleGuest()){
			return createFormWithPostMethod(LoginOrRegistrationContent.getInstance().getLoginContent(),LOGIN_OR_REGISTER_LINK);
		} else {
			return createFormWithPostMethod(LoginOrRegistrationContent.getInstance().getExitContent(),LOGIN_OR_REGISTER_LINK);
		}
		}

	public String createRegistrationForm(){
		return createFormWithPostMethod(LoginOrRegistrationContent.getInstance().getRegistrationContent(), LOGIN_OR_REGISTER_LINK);
	}
	
	public String createSuccessfulForm(){
		return createForm(LoginOrRegistrationContent.getInstance().getSuccessfulContent());
	}
	
	public String createFailureForm(String errorMessage){
		return createForm(LoginOrRegistrationContent.getInstance().getFailureContent(errorMessage));
	}
	
	public String createAfterRegistrationForm(String userName, String password){
		return createForm(LoginOrRegistrationContent.getInstance().getAfterRegistrationContent(userName, password));
	}

}
